class CreatePosts < ActiveRecord::Migration
  def self.up
    create_table :posts do |t|
      t.string  :title
      t.text    :body
      t.boolean :is_published
      t.integer :author_id
      t.integer :comments_count, :default => 0 #used for counter_cache feature

      t.timestamps
    end

    add_foreign_key('posts', 'author_id', 'users')
  end

  def self.down
    remove_foreign_key('posts', 'users')
    drop_table :posts
  end
end